<template>
	<view class="container">
		<uni-easyinput v-model="data.telephone" placeholder="请输入手机号" />
		<uni-easyinput v-model="data.password" placeholder="请输入密码" type="password" />
		<button type="primary" @click="login">登录</button>
		<button type="default" @click="register">注册</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: {
					"telephone": "12345678912",
					"password": "123456"
				}
			}
		},
		methods: {
			login() {
				uni.request({
					url: 'http://localhost:8090/foodapp/user/login',
					method: 'post',
					data: this.data,
					success: (res) => {
						if (res.data.success) {
							uni.setStorageSync("user", res.data.data)
							setTimeout(function() {
								uni.switchTab({
									url: "../my"
								})
							}, 1000);
							uni.showToast({
								icon: 'success',
								title: '登录成功'
							});

						} else {
							uni.showToast({
								icon: "none",
								title: '登录失败'
							});
						}
					},
					fail: () => {},
					complete: () => {}
				});

			},
			register(){
				uni.navigateTo({
					url:"../register/register"
				})
			}
		},
		onLoad() {

		}
	}
</script>

<style>

</style>
